import { createApp } from 'vue';
import ArcoVue from '@arco-design/web-vue';
import proComponents from '@arco-vue-pro-components/pro-components'
import ArcoVueIcon from '@arco-design/web-vue/es/icon';
import globalComponents from '@/components';
import route from './router';
import store from './store';
import directive from './directive';
import { createRouter, createWebHistory } from 'vue-router';
import './mock';
import App from './App.vue';
import { renderWithQiankun, qiankunWindow,} from "vite-plugin-qiankun/dist/helper";
// Styles are imported via arco-plugin. See config/plugin/arcoStyleImport.ts in the directory for details
// 样式通过 arco-plugin 插件导入。详见目录文件 config/plugin/arcoStyleImport.ts
// https://arco.design/docs/designlab/use-theme-package
import '@/assets/style/global.less';
import '@/api/interceptor';
import { isAuth } from '@/utils/auth';

let app;
let router;
const render = (container?,proxyBase?) => {
    // router = createRouter({
    //     history: createWebHistory(proxyBase || '/saas-service/'),
    //     routes,
    //       scrollBehavior() {
    //         return { top: 0 };
    //     },
    // })
    router = route
    app = createApp(App);
    app.directive('auth',{
        mounted(el, binding) {
            const { value: menuCode } = binding;
            const is = isAuth(menuCode)
        
            if (!is) {
              el.parentNode.removeChild(el);
            }
          }
    })
    app.use(router);
    app.use(ArcoVue, {});
    app.use(ArcoVueIcon);
    app.use(proComponents);

    app.use(store);
    app.use(globalComponents);
    app.use(directive);
    app.mount(container ? container : "#saas-service");
  };
// const app = createApp(App);


// app.mount('#app');
const initQianKun = () => {
// @ts-ignore
    renderWithQiankun({
        mount(props) {
            const { container,token,proxyBase } = props;
            console.log("mount",props,proxyBase)
            localStorage.setItem("token", token)
            render(container,proxyBase);
        },
        bootstrap(data?:any) {
            console.log("bootstrap",data)
        },
        unmount() {
         app.unmount();
         app = null
         router = null
        },
        update(props) {
        console.log('woshi chilid upadte----',props)
        }
    });
};
qiankunWindow && qiankunWindow.__POWERED_BY_QIANKUN__ ? initQianKun() : render();
